+2005-08-24 Øyvind Kolås <pippin@gimp.org>
+
+ * babl/babl-classes.c,
+ * babl/babl-classes.h,
+ * babl/babl-component.c,
+ * babl/babl-conversion.c,
+ * babl/babl-db.h,
+ * babl/babl-fish.c,
+ * babl/babl-fish.h,
+ * babl/babl-image.c,
+ * babl/babl-image.h,
+ * babl/babl-internal.h,
+ * babl/babl-introspect.c,
+ * babl/babl-model.c,
+ * babl/babl-model.h,
+ * babl/babl-pixel-format.c,
+ * babl/babl-pixel-format.h,
+ * babl/babl-sanity.c,
+ * babl/babl-sanity.h,
+ * babl/babl-type.c,
+ * babl/babl.c,
+ * babl/babl.h,
+ * babl/base/model-cmyk.c,
+ * babl/base/model-gray.c,
+ * babl/base/model-lab.c,
+ * babl/base/model-rgb.c,
+ * babl/base/model-ycbcr.c,
+ * tests/Makefile.am,
+ * tests/babl-html-dump.c,
+ * tests/babl_class_name.c,
+ * tests/float_to_u8.c,
+ * tests/grayscale_to_rgb.c,
+ * tests/rgb_to_lab_to_rgb.c,
+ * tests/rgb_to_ycbcr.c,
+ * tests/rgb_to_ycbcr_to_rgb.c,
+ * tests/u8_to_float.c: s/PixelFormat/Format/ (etc in other cases),
+ Made BablFish be more polymorphic (accept
+ format names as well as BablFormats).
+ * babl/babl-ids.h: reorganized, some renames.
+
+ * tests/srgb_to_lab_u8.c: new test for 8bit CIE Lab format (reference
+ data not correct yet).
+
+ * babl/base/type-u16.c,
+ * babl/base/type-u8.c: Added CIE fixed point data types.
+
+
2005-08-24 Øyvind Kolås <pippin@gimp.org>
* docs/babl.css: Added code highlighting classes.
"BablSampling",
"BablComponent",
"BablModel",
- "BablPixelFormat",
+ "BablFormat",
"BablConversion",
"BablConversionType",
"BablConversionTypePlanar",
"BablConversionModelPlanar",
- "BablConversionPixelFormat",
- "BablConversionPixelFormatPlanar",
+ "BablConversionFormat",
+ "BablConversionFormatPlanar",
"BablFish",
"BablFishReference",
"BablImage",
#ifndef _BABL_CLASSES_H
#define _BABL_CLASSES_H
-/* Type and PixelFormat */
+/* Type and Format */
typedef void (*BablFuncLinear) (void *src,
void *dst,
int n);
-/* TypePlanar, ModelPlanar and PixelFormatPlanar */
+/* TypePlanar, ModelPlanar and FormatPlanar */
typedef void (*BablFuncPlanar) (int src_bands,
void *src[],
int src_pitch[],
BABL_SAMPLING,
BABL_COMPONENT,
BABL_MODEL,
- BABL_PIXEL_FORMAT,
+ BABL_FORMAT,
BABL_CONVERSION,
BABL_CONVERSION_TYPE,
BABL_CONVERSION_TYPE_PLANAR,
BABL_CONVERSION_MODEL_PLANAR,
- BABL_CONVERSION_PIXEL_FORMAT,
- BABL_CONVERSION_PIXEL_FORMAT_PLANAR,
+ BABL_CONVERSION_FORMAT,
+ BABL_CONVERSION_FORMAT_PLANAR,
BABL_FISH,
BABL_FISH_REFERENCE,
typedef struct
{
BablConversion conversion;
-} BablConversionPixelFormat;
+} BablConversionFormat;
typedef struct
{
BablConversion conversion;
-} BablConversionPixelFormatPlanar;
+} BablConversionFormatPlanar;
typedef struct
{
BablComponent **component;
BablType **type;
BablSampling **sampling;
-} BablPixelFormat;
+} BablFormat;
typedef struct
{
BablSampling sampling;
BablComponent component;
BablModel model;
- BablPixelFormat pixel_format;
+ BablFormat format;
BablConversion conversion;
BablFish fish;
BablFishReference reference_fish;
else
{
- babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'",
+ babl_log ("%s(): unhandled parameter '%s' for format '%s'",
__FUNCTION__, arg, name);
exit (-1);
}
__FUNCTION__);
}
break;
- case BABL_PIXEL_FORMAT:
+ case BABL_FORMAT:
if (linear)
{
- babl = babl_calloc (sizeof (BablConversionPixelFormat), 1);
- babl->class_type = BABL_CONVERSION_PIXEL_FORMAT;
+ babl = babl_calloc (sizeof (BablConversionFormat), 1);
+ babl->class_type = BABL_CONVERSION_FORMAT;
babl->conversion.function.linear = linear;
}
else if (planar)
{
- babl = babl_calloc (sizeof (BablConversionPixelFormatPlanar), 1);
- babl->class_type = BABL_CONVERSION_PIXEL_FORMAT_PLANAR;
+ babl = babl_calloc (sizeof (BablConversionFormatPlanar), 1);
+ babl->class_type = BABL_CONVERSION_FORMAT_PLANAR;
babl->conversion.function.planar = planar;
}
else if (planar_bit)
}
else
{
- babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'",
+ babl_log ("%s(): unhandled parameter '%s' for format '%s'",
__FUNCTION__, arg, name);
exit (-1);
}
#define DB_INCREMENT_SIZE 16
#endif
+static inline int hash (char *str)
+{
+ int ret = 0;
+ int i = 1;
+
+ while (*str)
+ ret = (ret + ( i++ * (*str ++ & 31 ))) % 199;
+ return ret;
+}
/* file scope variables, for this .c file's database */
static int db_size = 0;
assert (BABL_IS_BABL (source));
assert (BABL_IS_BABL (destination));
- assert (source->class_type == BABL_PIXEL_FORMAT ||
+ assert (source->class_type == BABL_FORMAT ||
source->class_type == BABL_MODEL);
- assert (destination->class_type == BABL_PIXEL_FORMAT ||
+ assert (destination->class_type == BABL_FORMAT ||
destination->class_type == BABL_MODEL);
babl = babl_calloc (sizeof (BablFishReference), 1);
babl->fish.source = (union Babl*)source;
babl->fish.destination = (union Babl*)destination;
- if (source->class_type == BABL_PIXEL_FORMAT)
+ if (source->class_type == BABL_FORMAT)
{
babl->reference_fish.type_to_double =
babl_conversion_find (
- source->pixel_format.type[0],
+ source->format.type[0],
babl_type_id (BABL_DOUBLE)
);
babl->reference_fish.model_to_rgba =
babl_conversion_find (
- source->pixel_format.model,
+ source->format.model,
babl_model_id (BABL_RGBA)
);
babl->reference_fish.rgba_to_model =
babl_conversion_find (
babl_model_id (BABL_RGBA),
- destination->pixel_format.model
+ destination->format.model
);
babl->reference_fish.double_to_type =
babl_conversion_find (
babl_type_id (BABL_DOUBLE),
- destination->pixel_format.type[0]
+ destination->format.type[0]
);
}
else if (source->class_type == BABL_MODEL)
{
babl->reference_fish.type_to_double = NULL;
+ babl_log ("EEEEEEEEEEEEEEEEEEEEK!%s","!!!!");
babl->reference_fish.model_to_rgba =
babl_conversion_find (
- source->pixel_format.model,
+ source->format.model,
babl_model_id (BABL_RGBA)
);
babl->reference_fish.rgba_to_model =
babl_conversion_find (
babl_model_id (BABL_RGBA),
- destination->pixel_format.model
+ destination->format.model
);
babl->reference_fish.double_to_type =
babl_conversion_find (
babl_type_id (BABL_DOUBLE),
- destination->pixel_format.type[0]
+ destination->format.type[0]
);
}
}
Babl *
-babl_fish (Babl *source,
- Babl *destination)
+babl_fish (void *source,
+ void *destination)
{
- return babl_fish_reference_new (source, destination);
+ Babl *source_format = NULL;
+ Babl *destination_format = NULL;
+
+ assert (source);
+ assert (destination);
+
+ if (BABL_IS_BABL (source))
+ {
+ source_format = source;
+ }
+
+ if (!source_format)
+ {
+ source_format = babl_format ((char*)source);
+ }
+
+ if (!source_format)
+ {
+ babl_log ("%s(%p, %p) source format invalid",
+ __FUNCTION__, source, destination);
+ }
+
+ if (BABL_IS_BABL (destination))
+ {
+ destination_format = destination;
+ }
+
+ if (!destination_format)
+ {
+ destination_format = babl_format ((char*)destination);
+ }
+
+ if (!destination_format)
+ {
+ babl_log ("%s(%p, %p) destination format invalid",
+ __FUNCTION__, source, destination);
+ }
+
+ return babl_fish_reference_new (source_format, destination_format);
}
void *fooA;
#define BABL_MAX_BANDS 32
+/* should perhaps have been babl_fish_process, but the public api
+ * is shorther and makes sense for the API
+ */
int
-babl_fish_process (Babl *babl,
- void *source,
- void *destination,
- int n)
+babl_process (Babl *babl,
+ void *source,
+ void *destination,
+ int n)
{
Babl *imageA;
Babl *imageB;
babl_conversion_process (babl->reference_fish.type_to_double,
source, fooA,
- n * BABL(babl->fish.source)->pixel_format.bands);
+ n * BABL(babl->fish.source)->format.bands);
/* calculate planar representation of fooA, and fooB */
- imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> pixel_format.model));
+ imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> format.model));
imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA));
/* transform fooA into fooB fooB is rgba double */
imageB = babl_image_new_from_linear (
fooB, babl_model_id (BABL_RGBA));
imageC = babl_image_new_from_linear (
- fooA, BABL(BABL((babl->fish.destination))->pixel_format.model));
+ fooA, BABL(BABL((babl->fish.destination))->format.model));
babl_conversion_process (babl->reference_fish.rgba_to_model,
imageB, imageC,
/* working directly on linear buffers */
babl_conversion_process (babl->reference_fish.double_to_type,
fooA, destination,
- n * BABL(babl->fish.destination)->pixel_format.bands);
+ n * BABL(babl->fish.destination)->format.bands);
babl_free (imageB);
babl_free (imageC);
BABL_DEFINE_CLASS_NO_NEW_NO_ID(babl_fish)
/** create a new BablFish capable of translating between the pixel
- * formats given in source and destination. (use babl_pixel_format (string))
+ * formats given in source and destination. (use babl_format (string))
*/
-Babl * babl_fish (Babl *source,
- Babl *destination);
+Babl * babl_fish (void *source,
+ void *destination);
/* Transform n pixels from source into destination,
* source and destination can be pointers to linear buffers
* (or at a later stage of babl development BablImages)
*/
-int babl_fish_process (Babl *babl_fish,
+int babl_process (Babl *babl_fish,
void *source,
void *destination,
int n);
#define BABL_MAX_BANDS 32
static int
-each_babl_pixel_format_destroy (Babl *babl,
+each_babl_format_destroy (Babl *babl,
void *data)
{
- babl_free (babl->pixel_format.from);
- babl_free (babl->pixel_format.to);
+ babl_free (babl->format.from);
+ babl_free (babl->format.to);
babl_free (babl);
return 0; /* continue iterating */
}
static Babl *
-pixel_format_new (const char *name,
+format_new (const char *name,
int id,
int planar,
int bands,
int band;
/* allocate all memory in one chunk */
- babl = babl_calloc (sizeof (BablPixelFormat) +
+ babl = babl_calloc (sizeof (BablFormat) +
strlen (name) + 1 +
sizeof (BablComponent*) * (bands+1) +
sizeof (BablSampling*) * (bands+1) +
sizeof (int) * (bands+1) +
sizeof (int) * (bands+1),1);
- babl->pixel_format.component = ((void *)babl) + sizeof (BablPixelFormat);
- babl->pixel_format.type = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1);
- babl->pixel_format.sampling = ((void *)babl->pixel_format.type) + sizeof (BablType*) * (bands+1);
- babl->instance.name = ((void *)babl->pixel_format.sampling) + sizeof (BablSampling*) * (bands+1);
+ babl->format.component = ((void *)babl) + sizeof (BablFormat);
+ babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (bands+1);
+ babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (bands+1);
+ babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (bands+1);
- babl->class_type = BABL_PIXEL_FORMAT;
+ babl->class_type = BABL_FORMAT;
babl->instance.id = id;
strcpy (babl->instance.name, name);
- babl->pixel_format.model = model;
- babl->pixel_format.bands = bands;
- babl->pixel_format.planar = planar;
+ babl->format.model = model;
+ babl->format.bands = bands;
+ babl->format.planar = planar;
for (band=0; band < bands; band++)
{
- babl->pixel_format.component[band] = component[band];
- babl->pixel_format.type[band] = type[band];
- babl->pixel_format.sampling[band] = sampling[band];
+ babl->format.component[band] = component[band];
+ babl->format.type[band] = type[band];
+ babl->format.sampling[band] = sampling[band];
}
- babl->pixel_format.component[band] = NULL;
- babl->pixel_format.type[band] = NULL;
- babl->pixel_format.sampling[band] = NULL;
+ babl->format.component[band] = NULL;
+ babl->format.type[band] = NULL;
+ babl->format.sampling[band] = NULL;
return babl;
}
Babl *
-babl_pixel_format_new (const char *name,
+babl_format_new (const char *name,
...)
{
va_list varg;
model = (BablModel*)arg;
break;
case BABL_INSTANCE:
- case BABL_PIXEL_FORMAT:
+ case BABL_FORMAT:
case BABL_CONVERSION:
case BABL_CONVERSION_TYPE:
case BABL_CONVERSION_TYPE_PLANAR:
case BABL_CONVERSION_MODEL_PLANAR:
- case BABL_CONVERSION_PIXEL_FORMAT:
- case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
+ case BABL_CONVERSION_FORMAT:
+ case BABL_CONVERSION_FORMAT_PLANAR:
case BABL_FISH:
case BABL_FISH_REFERENCE:
case BABL_IMAGE:
else
{
- babl_log ("%s: unhandled parameter '%s' for pixel_format '%s'",
+ babl_log ("%s: unhandled parameter '%s' for format '%s'",
__FUNCTION__, arg, name);
exit (-1);
}
va_end (varg);
- babl = pixel_format_new (name, id,
+ babl = format_new (name, id,
planar, bands, model,
component, sampling, type);
}
else
{
- each_babl_pixel_format_destroy (babl, NULL);
+ each_babl_format_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE (babl_pixel_format)
+BABL_CLASS_TEMPLATE (babl_format)
* Boston, MA 02111-1307, USA.
*/
-#ifndef _BABL_PIXEL_FORMAT_H
-#define _BABL_PIXEL_FORMAT_H
+#ifndef _BABL_FORMAT_H
+#define _BABL_FORMAT_H
#include "babl-classes.h"
-BABL_DEFINE_CLASS (babl_pixel_format)
+BABL_DEFINE_CLASS (babl_format)
#endif
BABL_DOUBLE,
BABL_HALF_FLOAT,
- BABL_COMPONENT_BASE = 1000,
+ BABL_U8_LUMA,
+ BABL_U8_CHROMA,
+ BABL_U16_CIE_L,
+ BABL_U16_CIE_AB,
+ BABL_U8_CIE_L,
+ BABL_U8_CIE_AB,
+
+ BABL_MODEL_BASE = 1000,
+ BABL_RGB,
+ BABL_RGBA,
+ BABL_RGB_GAMMA_2_2,
+ BABL_RGBA_GAMMA_2_2,
+ BABL_RGBA_PREMULTIPLIED,
+ BABL_GRAY,
+ BABL_GRAY_ALPHA,
+ BABL_GRAY_GAMMA_2_2,
+ BABL_GRAY_GAMMA_2_2_ALPHA,
+ BABL_GRAY_ALPHA_PREMULTIPLIED,
+ BABL_YCBCR,
+ BABL_YCBCR_ALPHA,
+ BABL_CIE_LAB,
+ BABL_CIE_LAB_ALPHA,
+ BABL_CMY,
+ BABL_CMYK,
+ BABL_CMYK_ALPHA,
+
+ BABL_COMPONENT_BASE = 10000,
BABL_RED,
BABL_GREEN,
BABL_BLUE,
BABL_X,
BABL_Y,
BABL_Z,
- BABL_LAB_L,
- BABL_LAB_A,
- BABL_LAB_B,
+ BABL_CIE_L,
+ BABL_CIE_A,
+ BABL_CIE_B,
BABL_CB,
BABL_CR,
BABL_CYAN,
BABL_Z_BUFFER,
BABL_PADDING,
- BABL_MODEL_BASE = 10000,
- BABL_RGB,
- BABL_RGBA,
- BABL_RGB_GAMMA_2_2,
- BABL_RGBA_GAMMA_2_2,
- BABL_RGBA_PREMULTIPLIED,
- BABL_GRAY,
- BABL_GRAY_ALPHA,
- BABL_GRAY_GAMMA_2_2,
- BABL_GRAY_GAMMA_2_2_ALPHA,
- BABL_GRAY_ALPHA_PREMULTIPLIED,
- BABL_YCBCR,
- BABL_YCBCR_ALPHA,
- BABL_LAB,
- BABL_LAB_ALPHA,
- BABL_CMY,
- BABL_CMYK,
- BABL_CMYK_ALPHA,
- BABL_PIXEL_FORMAT_BASE = 100000,
+ BABL_FORMAT_BASE = 100000,
BABL_SRGB,
BABL_SRGBA,
BABL_RGB_FLOAT,
BABL_RGBA_FLOAT,
BABL_RGBA_DOUBLE,
BABL_LAB_FLOAT,
- BABL_YUV420,
+ BABL_LAB_U16,
+ BABL_LAB_U8,
BABL_RGB_U8,
BABL_RGBA_U8,
BABL_RGBA_U16,
BABL_CMYK_FLOAT,
BABL_CMYK_ALPHA_FLOAT,
- BABL_YUV411,
- BABL_YUV422,
+ BABL_YCBCR411,
+ BABL_YCBCR422,
+ BABL_YCBCR420,
BABL_PIXEL_USER_BASE,
};
int calc_pitch=0;
assert (format);
- assert (format->class_type == BABL_PIXEL_FORMAT ||
+ assert (format->class_type == BABL_FORMAT ||
format->class_type == BABL_MODEL);
switch (format->class_type)
{
- case BABL_PIXEL_FORMAT:
- for (band=0; band < format->pixel_format.bands; band++)
+ case BABL_FORMAT:
+ for (band=0; band < format->format.bands; band++)
{
- BablType *type = format->pixel_format.type[band];
+ BablType *type = format->format.type[band];
calc_pitch += (type->bits / 8);
}
- for (band=0; band < format->pixel_format.bands; band++)
+ for (band=0; band < format->format.bands; band++)
{
- BablType *type = format->pixel_format.type[band];
+ BablType *type = format->format.type[band];
- component[band] = format->pixel_format.component[band];
+ component[band] = format->format.component[band];
data[band] = buffer + offset;
pitch[band] = calc_pitch;
stride[band] = 0;
}
else
{
- new_component = (BablComponent*)babl_component (arg);
+ new_component = (BablComponent*) babl_component (arg);
}
+ /* FIXME: add error checking */
component [bands] = new_component;
data [bands] = va_arg (varg, void*);
pitch [bands] = va_arg (varg, int);
if (bands>=BABL_MAX_BANDS)
{
- babl_log ("%s(): maximum number of bands (%i) exceeded for BablImage",
+ babl_log ("%s(): maximum number of bands (%i) exceeded",
__FUNCTION__, BABL_MAX_BANDS);
}
Babl * babl_image_new (void *first_component,
...);
-/* create a new BablImage based on a packed BablPixelFormat (or BablModel which
+/* create a new BablImage based on a packed BablFormat (or BablModel which
* is a virtual pixelformat based on the BablModel using only doubles in the
* order they are listed in the model.
*/
"BablSampling",
"BablComponent",
"BablModel",
- "BablPixelFormat",
+ "BablFormat",
"BablConversion",
"BablConversionType",
"BablConversionTypePlanar",
"BablConversionModelPlanar",
- "BablConversionPixelFormat",
- "BablConversionPixelFormatPlanar",
+ "BablConversionFormat",
+ "BablConversionFormatPlanar",
"BablFish",
"BablFishReference",
"BablImage",
babl = db_exist (id, NULL); \
if (!babl) \
{ \
- babl_log ("%s(\"%i\"): not found", __FUNCTION__, id); \
+ babl_log ("%s(%i): not found", __FUNCTION__, id); \
} \
return babl; \
}
static void sampling_introspect (Babl *babl);
static void model_introspect (Babl *babl);
static void type_introspect (Babl *babl);
-static void pixel_format_introspect (Babl *babl);
+static void format_introspect (Babl *babl);
static int each_introspect (Babl *babl,
void *user_data);
babl_model_each (each_introspect, NULL);
babl_log ("%s","");
babl_log ("Pixel formats:%s", "");
- babl_pixel_format_each (each_introspect, NULL);
+ babl_format_each (each_introspect, NULL);
babl_log ("%s","");
babl_log ("conversions:%s", "");
babl_conversion_each (each_introspect, NULL);
static void
-pixel_format_introspect (Babl *babl)
+format_introspect (Babl *babl)
{
int i;
- babl_log ("\t\tplanar=%i", babl->pixel_format.planar);
- babl_log ("\t\tbands=%i", babl->pixel_format.bands);
+ babl_log ("\t\tplanar=%i", babl->format.planar);
+ babl_log ("\t\tbands=%i", babl->format.bands);
- for (i=0; i< babl->pixel_format.bands; i++)
+ for (i=0; i< babl->format.bands; i++)
{
babl_log ("\t\tband[%i] type='%s' component='%s' sampling='%s'",
- i, babl->pixel_format.type[i]->instance.name,
- babl->pixel_format.component[i]->instance.name,
- babl->pixel_format.sampling[i]->instance.name);
+ i, babl->format.type[i]->instance.name,
+ babl->format.component[i]->instance.name,
+ babl->format.sampling[i]->instance.name);
}
}
model_introspect (babl);
item_conversions_introspect (babl);
break;
- case BABL_PIXEL_FORMAT:
- pixel_format_introspect (babl);
+ case BABL_FORMAT:
+ format_introspect (babl);
item_conversions_introspect (babl);
break;
case BABL_SAMPLING:
case BABL_TYPE:
case BABL_SAMPLING:
case BABL_INSTANCE:
- case BABL_PIXEL_FORMAT:
+ case BABL_FORMAT:
case BABL_CONVERSION:
case BABL_CONVERSION_TYPE:
case BABL_CONVERSION_TYPE_PLANAR:
case BABL_CONVERSION_MODEL_PLANAR:
- case BABL_CONVERSION_PIXEL_FORMAT:
- case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
+ case BABL_CONVERSION_FORMAT:
+ case BABL_CONVERSION_FORMAT_PLANAR:
case BABL_FISH:
case BABL_FISH_REFERENCE:
case BABL_IMAGE:
* Boston, MA 02111-1307, USA.
*/
-#ifndef _BABL_pixel_format_H
-#define _BABL_pixel_format_H
+#ifndef _BABL_format_H
+#define _BABL_format_H
#include "babl-classes.h"
BABL_DEFINE_CLASS (babl_model)
#define BABL_MAX_BANDS 32
static int
-each_babl_pixel_format_destroy (Babl *babl,
+each_babl_format_destroy (Babl *babl,
void *data)
{
- babl_free (babl->pixel_format.from);
- babl_free (babl->pixel_format.to);
+ babl_free (babl->format.from);
+ babl_free (babl->format.to);
babl_free (babl);
return 0; /* continue iterating */
}
static Babl *
-pixel_format_new (const char *name,
+format_new (const char *name,
int id,
int planar,
int bands,
int band;
/* allocate all memory in one chunk */
- babl = babl_calloc (sizeof (BablPixelFormat) +
+ babl = babl_calloc (sizeof (BablFormat) +
strlen (name) + 1 +
sizeof (BablComponent*) * (bands+1) +
sizeof (BablSampling*) * (bands+1) +
sizeof (int) * (bands+1) +
sizeof (int) * (bands+1),1);
- babl->pixel_format.component = ((void *)babl) + sizeof (BablPixelFormat);
- babl->pixel_format.type = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1);
- babl->pixel_format.sampling = ((void *)babl->pixel_format.type) + sizeof (BablType*) * (bands+1);
- babl->instance.name = ((void *)babl->pixel_format.sampling) + sizeof (BablSampling*) * (bands+1);
+ babl->format.component = ((void *)babl) + sizeof (BablFormat);
+ babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (bands+1);
+ babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (bands+1);
+ babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (bands+1);
- babl->class_type = BABL_PIXEL_FORMAT;
+ babl->class_type = BABL_FORMAT;
babl->instance.id = id;
strcpy (babl->instance.name, name);
- babl->pixel_format.model = model;
- babl->pixel_format.bands = bands;
- babl->pixel_format.planar = planar;
+ babl->format.model = model;
+ babl->format.bands = bands;
+ babl->format.planar = planar;
for (band=0; band < bands; band++)
{
- babl->pixel_format.component[band] = component[band];
- babl->pixel_format.type[band] = type[band];
- babl->pixel_format.sampling[band] = sampling[band];
+ babl->format.component[band] = component[band];
+ babl->format.type[band] = type[band];
+ babl->format.sampling[band] = sampling[band];
}
- babl->pixel_format.component[band] = NULL;
- babl->pixel_format.type[band] = NULL;
- babl->pixel_format.sampling[band] = NULL;
+ babl->format.component[band] = NULL;
+ babl->format.type[band] = NULL;
+ babl->format.sampling[band] = NULL;
return babl;
}
Babl *
-babl_pixel_format_new (const char *name,
+babl_format_new (const char *name,
...)
{
va_list varg;
model = (BablModel*)arg;
break;
case BABL_INSTANCE:
- case BABL_PIXEL_FORMAT:
+ case BABL_FORMAT:
case BABL_CONVERSION:
case BABL_CONVERSION_TYPE:
case BABL_CONVERSION_TYPE_PLANAR:
case BABL_CONVERSION_MODEL_PLANAR:
- case BABL_CONVERSION_PIXEL_FORMAT:
- case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
+ case BABL_CONVERSION_FORMAT:
+ case BABL_CONVERSION_FORMAT_PLANAR:
case BABL_FISH:
case BABL_FISH_REFERENCE:
case BABL_IMAGE:
else
{
- babl_log ("%s: unhandled parameter '%s' for pixel_format '%s'",
+ babl_log ("%s: unhandled parameter '%s' for format '%s'",
__FUNCTION__, arg, name);
exit (-1);
}
va_end (varg);
- babl = pixel_format_new (name, id,
+ babl = format_new (name, id,
planar, bands, model,
component, sampling, type);
}
else
{
- each_babl_pixel_format_destroy (babl, NULL);
+ each_babl_format_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE (babl_pixel_format)
+BABL_CLASS_TEMPLATE (babl_format)
* Boston, MA 02111-1307, USA.
*/
-#ifndef _BABL_PIXEL_FORMAT_H
-#define _BABL_PIXEL_FORMAT_H
+#ifndef _BABL_FORMAT_H
+#define _BABL_FORMAT_H
#include "babl-classes.h"
-BABL_DEFINE_CLASS (babl_pixel_format)
+BABL_DEFINE_CLASS (babl_format)
#endif
#include "babl.h"
#include "babl-internal.h"
+
+static int OK;
static int
foo (Babl *babl,
}
}
if (!ok)
- babl_log ("lack of sanity! type '%s' has no conversion to double",
- babl->instance.name);
+ {
+ OK = 0;
+ babl_log ("lack of sanity! type '%s' has no conversion to double",
+ babl->instance.name);
+ }
ok = 0;
}
}
if (!ok)
- babl_log ("lack of sanity! type '%s' has no conversion from double",
- babl->instance.name);
+ {
+ OK=0;
+ babl_log ("lack of sanity! type '%s' has no conversion from double",
+ babl->instance.name);
+ }
return 0;
}
}
}
if (!ok)
- babl_log ("lack of sanity! model '%s' has no conversion to 'rgba'",
- babl->instance.name);
+ {
+ OK=0;
+ babl_log ("lack of sanity! model '%s' has no conversion to 'rgba'",
+ babl->instance.name);
+ }
ok = 0;
}
}
if (!ok)
- babl_log ("lack of sanity! model '%s' has no conversion from 'rgba'",
- babl->instance.name);
+ {
+ babl_log ("lack of sanity! model '%s' has no conversion from 'rgba'",
+ babl->instance.name);
+ OK=0;
+ }
return 0;
}
{
if (0 == babl->instance.id)
{
+ OK=0;
babl_log ("%s\t'%s' has id==0",
babl_class_name (babl->class_type), babl->instance.name);
}
return 0;
}
-void
+int
babl_sanity (void)
{
+ OK=1;
+
babl_type_each (id_sanity, NULL);
babl_component_each (id_sanity, NULL);
babl_model_each (id_sanity, NULL);
- babl_pixel_format_each (id_sanity, NULL);
+ babl_format_each (id_sanity, NULL);
babl_type_each (type_sanity, NULL);
babl_sampling_each (foo, NULL);
babl_component_each (foo, NULL);
babl_model_each (model_sanity, NULL);
- babl_pixel_format_each (foo, NULL);
+ babl_format_each (foo, NULL);
babl_conversion_each (foo, NULL);
-
-
+ return OK;
}
static Babl *babl_conversion_source (Babl *babl)
#ifndef _BABL_SANITY_H
#define _BABL_SANITY_H
-void babl_sanity (void);
+int babl_sanity (void);
#endif
{
va_list varg;
Babl *babl;
- int id = 0;
- int bits = 0;
+ int id = 0;
+ int is_integer = 0;
+ int bits = 0;
+ long min = 0;
+ long max = 255;
+ double min_val = 0.0;
+ double max_val = 0.0;
const char *arg=name;
else if (!strcmp (arg, "bits"))
{
bits = va_arg (varg, int);
+ min = 0;
+ max = 1<<bits;
+ }
+ else if (!strcmp (arg, "integer"))
+ {
+ is_integer = va_arg (varg, int);
+ }
+ else if (!strcmp (arg, "min"))
+ {
+ min = va_arg (varg, long);
+ }
+ else if (!strcmp (arg, "max"))
+ {
+ max = va_arg (varg, long);
+ }
+ else if (!strcmp (arg, "min_val"))
+ {
+ min_val = va_arg (varg, double);
+ }
+ else if (!strcmp (arg, "max_val"))
+ {
+ max_val = va_arg (varg, double);
}
else
{
- babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'",
+ babl_log ("%s(): unhandled parameter '%s' for format '%s'",
__FUNCTION__, arg, name);
exit (-1);
}
babl_sampling_init ();
babl_component_init ();
babl_model_init ();
- babl_pixel_format_init ();
+ babl_format_init ();
babl_conversion_init ();
babl_base_init ();
babl_sanity ();
{
babl_fish_destroy ();
babl_conversion_destroy ();
- babl_pixel_format_destroy ();
+ babl_format_destroy ();
babl_model_destroy ();
babl_component_destroy ();
babl_sampling_destroy ();
void babl_init (void);
-void babl_sanity (void);
void babl_introspect (void);
void babl_destroy (void);
static void components (void);
static void models (void);
static void conversions (void);
-static void pixel_formats (void);
+static void formats (void);
void
babl_base_model_cmyk (void)
components ();
models ();
conversions ();
- pixel_formats ();
+ formats ();
}
static void
}
static void
-pixel_formats (void)
+formats (void)
{
}
NULL);
babl_component_new (
- "Y-g2.2",
+ "Y'",
"id", BABL_LUMINANCE_GAMMA_2_2,
"luma",
NULL);
NULL);
babl_model_new (
- "gray-g2.2",
+ "gray'",
"id", BABL_GRAY_GAMMA_2_2,
babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
NULL);
babl_model_new (
- "graya-g2.2",
+ "gray'a",
"id", BABL_GRAY_GAMMA_2_2_ALPHA,
babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
babl_component_id (BABL_ALPHA),
conversions (void)
{
babl_conversion_new (
- "babl-base: gray-g2.2 to rgba",
+ "babl-base: gray' to rgba",
"source", babl_model_id (BABL_GRAY_GAMMA_2_2),
"destination", babl_model_id (BABL_RGBA),
"planar", gray_2_2_to_rgb,
babl_conversion_new (
- "babl-base: rgba to gray-g2.2",
+ "babl-base: rgba to gray'",
"source", babl_model_id (BABL_RGBA),
"destination", babl_model_id (BABL_GRAY_GAMMA_2_2),
"planar", rgb_to_gray_2_2,
);
babl_conversion_new (
- "babl-base: graya-g2.2 to rgba",
+ "babl-base: gray'a to rgba",
"source", babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
"destination", babl_model_id (BABL_RGBA),
"planar", gray_2_2_to_rgb,
);
babl_conversion_new (
- "babl-base: rgba to graya-g2.2",
+ "babl-base: rgba to gray'a",
"source", babl_model_id (BABL_RGBA),
"destination", babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
"planar", rgb_to_gray_2_2,
static void components (void);
static void models (void);
static void conversions (void);
-static void pixel_formats (void);
+static void formats (void);
void
babl_base_model_lab (void)
components ();
models ();
conversions ();
- pixel_formats ();
+ formats ();
}
static void
{
babl_component_new (
"CIE L",
- "id", BABL_LAB_L,
- "luma",
+ "id", BABL_CIE_L,
NULL);
babl_component_new (
"CIE a",
- "id", BABL_LAB_A,
+ "id", BABL_CIE_A,
"chroma",
NULL);
babl_component_new (
"CIE b",
- "id", BABL_LAB_B,
+ "id", BABL_CIE_B,
"chroma",
NULL);
}
{
babl_model_new (
"CIE Lab",
- "id", BABL_LAB,
- babl_component_id (BABL_LAB_L),
- babl_component_id (BABL_LAB_A),
- babl_component_id (BABL_LAB_B),
+ "id", BABL_CIE_LAB,
+ babl_component_id (BABL_CIE_L),
+ babl_component_id (BABL_CIE_A),
+ babl_component_id (BABL_CIE_B),
NULL);
babl_model_new (
"CIE Lab alpha",
- "id", BABL_LAB_ALPHA,
- babl_component_id (BABL_LAB_L),
- babl_component_id (BABL_LAB_A),
- babl_component_id (BABL_LAB_B),
+ "id", BABL_CIE_LAB_ALPHA,
+ babl_component_id (BABL_CIE_L),
+ babl_component_id (BABL_CIE_A),
+ babl_component_id (BABL_CIE_B),
babl_component_id (BABL_ALPHA),
NULL);
}
conversions (void)
{
babl_conversion_new (
- "babl-base: rgba to lab",
+ "babl-base: rgba to cie-lab",
"source", babl_model_id (BABL_RGBA),
- "destination", babl_model_id (BABL_LAB),
+ "destination", babl_model_id (BABL_CIE_LAB),
"planar", rgb_to_lab,
NULL
);
babl_conversion_new (
- "babl-base: lab to rgba",
- "source", babl_model_id (BABL_LAB),
+ "babl-base: cie-lab to rgba",
+ "source", babl_model_id (BABL_CIE_LAB),
"destination", babl_model_id (BABL_RGBA),
"planar", lab_to_rgb,
NULL
);
babl_conversion_new (
- "babl-base: rgb to lab",
+ "babl-base: rgb to cie-lab",
"source", babl_model_id (BABL_RGB),
- "destination", babl_model_id (BABL_LAB),
+ "destination", babl_model_id (BABL_CIE_LAB),
"planar", rgb_to_lab,
NULL
);
babl_conversion_new (
- "babl-base: lab to rgb",
- "source", babl_model_id (BABL_LAB),
+ "babl-base: cie-lab to rgb",
+ "source", babl_model_id (BABL_CIE_LAB),
"destination", babl_model_id (BABL_RGB),
"planar", lab_to_rgb,
NULL
);
babl_conversion_new (
- "babl-base: rgba to laba",
+ "babl-base: rgba to cie-lab-float",
"source", babl_model_id (BABL_RGBA),
- "destination", babl_model_id (BABL_LAB_ALPHA),
+ "destination", babl_model_id (BABL_CIE_LAB_ALPHA),
"planar", rgb_to_lab,
NULL
);
babl_conversion_new (
- "babl-base: laba to rgba",
- "source", babl_model_id (BABL_LAB_ALPHA),
+ "babl-base: cie-lab-float to rgba",
+ "source", babl_model_id (BABL_CIE_LAB_ALPHA),
"destination", babl_model_id (BABL_RGBA),
"planar", lab_to_rgb,
NULL
}
static void
-pixel_formats (void)
+formats (void)
{
- babl_pixel_format_new (
- "lab-float",
+ babl_format_new (
+ "cie-lab-float",
"id", BABL_LAB_FLOAT,
- babl_model_id (BABL_LAB),
+ babl_model_id (BABL_CIE_LAB),
babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LAB_L),
- babl_component_id (BABL_LAB_A),
- babl_component_id (BABL_LAB_B),
+ babl_component_id (BABL_CIE_L),
+ babl_component_id (BABL_CIE_A),
+ babl_component_id (BABL_CIE_B),
+ NULL);
+
+ babl_format_new (
+ "cie-lab-u8",
+ "id", BABL_LAB_U8,
+ babl_model_id (BABL_CIE_LAB),
+ babl_type_id (BABL_U8_CIE_L),
+ babl_component_id (BABL_CIE_L),
+ babl_type_id (BABL_U8_CIE_AB),
+ babl_component_id (BABL_CIE_A),
+ babl_type_id (BABL_U8_CIE_AB),
+ babl_component_id (BABL_CIE_B),
+ NULL);
+
+ babl_format_new (
+ "cie-lab-u16",
+ "id", BABL_LAB_U16,
+ babl_model_id (BABL_CIE_LAB),
+ babl_type_id (BABL_U16_CIE_L),
+ babl_component_id (BABL_CIE_L),
+ babl_type_id (BABL_U16_CIE_AB),
+ babl_component_id (BABL_CIE_A),
+ babl_type_id (BABL_U16_CIE_AB),
+ babl_component_id (BABL_CIE_B),
NULL);
}
static void models (void);
static void components (void);
static void conversions (void);
-static void pixel_formats (void);
+static void formats (void);
void
babl_base_model_rgb (void)
components ();
models ();
conversions ();
- pixel_formats ();
+ formats ();
}
static void
NULL);
babl_component_new (
- "R-g2.2",
+ "R'",
"id", BABL_RED_GAMMA_2_2,
"luma",
"chroma",
NULL);
babl_component_new (
- "G-g2.2",
+ "G'",
"id", BABL_GREEN_GAMMA_2_2,
"luma",
"chroma",
NULL);
babl_component_new (
- "B-g2.2",
+ "B'",
"id", BABL_BLUE_GAMMA_2_2,
"luma",
"chroma",
NULL);
babl_model_new (
- "rgb-g2.2",
+ "rgb'",
"id", BABL_RGB_GAMMA_2_2,
babl_component_id (BABL_RED_GAMMA_2_2),
babl_component_id (BABL_GREEN_GAMMA_2_2),
NULL);
babl_model_new (
- "rgba-g2.2",
+ "rgb'a",
"id", BABL_RGBA_GAMMA_2_2,
babl_component_id (BABL_RED_GAMMA_2_2),
babl_component_id (BABL_GREEN_GAMMA_2_2),
}
for (;band<dst_bands;band++)
{
- *(double*)dst[band] = *(double*) src[band];
+ if (band<src_bands)
+ *(double*)dst[band] = *(double*) src[band];
+ else
+ *(double*)dst[band] = 1.0;
}
BABL_PLANAR_STEP
}
}
static void
-pixel_formats (void)
+formats (void)
{
- babl_pixel_format_new (
+ babl_format_new (
"srgb",
"id", BABL_SRGB,
babl_model_id (BABL_RGB_GAMMA_2_2),
babl_component_id (BABL_BLUE_GAMMA_2_2),
NULL);
- babl_pixel_format_new (
+ babl_format_new (
"srgba",
"id", BABL_SRGBA,
babl_model_id (BABL_RGBA_GAMMA_2_2),
babl_component_id (BABL_ALPHA),
NULL);
- babl_pixel_format_new (
+ babl_format_new (
"rgba-float",
"id", BABL_RGBA_FLOAT,
babl_model_id (BABL_RGBA),
babl_component_id (BABL_ALPHA),
NULL);
- babl_pixel_format_new (
+ babl_format_new (
"rgba-double",
"id", BABL_RGBA_DOUBLE,
babl_model_id (BABL_RGBA),
babl_component_id (BABL_ALPHA),
NULL);
- babl_pixel_format_new (
+ babl_format_new (
"rgb-float",
"id", BABL_RGB_FLOAT,
babl_model_id (BABL_RGB),
static void components (void);
static void models (void);
static void conversions (void);
-static void pixel_formats (void);
+static void formats (void);
void
babl_base_model_ycbcr (void)
components ();
models ();
conversions ();
- pixel_formats ();
+ formats ();
}
static void
models (void)
{
babl_model_new (
- "ycbcr",
+ "y'cbcr",
"id", BABL_YCBCR,
babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
babl_component_id (BABL_CB),
NULL);
babl_model_new (
- "ycbcra",
+ "y'cbcra",
"id", BABL_YCBCR_ALPHA,
babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
babl_component_id (BABL_CB),
conversions (void)
{
babl_conversion_new (
- "babl-base: rgba to ycbcr",
+ "babl-base: rgba to y'cbcr",
"source", babl_model_id (BABL_RGBA),
"destination", babl_model_id (BABL_YCBCR),
"planar", rgb_to_ycbcr,
NULL
);
babl_conversion_new (
- "babl-base: ycbcr to rgba",
+ "babl-base: y'cbcr to rgba",
"source", babl_model_id (BABL_YCBCR),
"destination", babl_model_id (BABL_RGBA),
"planar", ycbcr_to_rgb,
NULL
);
babl_conversion_new (
- "babl-base: rgb to ycbcr",
+ "babl-base: rgb to y'cbcr",
"source", babl_model_id (BABL_RGB),
"destination", babl_model_id (BABL_YCBCR),
"planar", rgb_to_ycbcr,
NULL
);
babl_conversion_new (
- "babl-base: ycbcr to rgb",
+ "babl-base: y'cbcr to rgb",
"source", babl_model_id (BABL_YCBCR),
"destination", babl_model_id (BABL_RGB),
"planar", ycbcr_to_rgb,
NULL
);
babl_conversion_new (
- "babl-base: rgba to ycbcra",
+ "babl-base: rgba to y'cbcra",
"source", babl_model_id (BABL_RGBA),
"destination", babl_model_id (BABL_YCBCR_ALPHA),
"planar", rgb_to_ycbcr,
NULL
);
babl_conversion_new (
- "babl-base: ycbcra to rgba",
+ "babl-base: y'cbcra to rgba",
"source", babl_model_id (BABL_YCBCR_ALPHA),
"destination", babl_model_id (BABL_RGBA),
"planar", ycbcr_to_rgb,
}
static void
-pixel_formats (void)
+formats (void)
{
-#if 0
- babl_pixel_format_new (
- "yuv420",
- "id", BABL_YUV420,
+ babl_format_new (
+ "y'cbcr420",
+ "id", BABL_YCBCR420,
"planar",
babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_U8),
- babl_sampling (1, 1), babl_component_id (BABL_LUMINANCE),
- babl_sampling (2, 2), babl_component_id (BABL_CB),
- babl_sampling (2, 2), babl_component_id (BABL_CR),
+ babl_type_id (BABL_U8_LUMA),
+ babl_sampling (1, 1),
+ babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_sampling (2, 2),
+ babl_component_id (BABL_CB),
+ babl_sampling (2, 2),
+ babl_component_id (BABL_CR),
NULL);
- babl_pixel_format_new (
- "yuv411",
- "id", BABL_YUV411,
+
+ babl_format_new (
+ "y'cbcr422",
+ "id", BABL_YCBCR422,
"planar",
- babl_type ("u8"),
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
babl_sampling (1, 1),
- babl_component ("Y"),
- babl_sampling (4, 1),
+ babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_sampling (2, 1),
babl_component_id (BABL_CB),
- babl_sampling (4, 1),
+ babl_sampling (2, 1),
babl_component_id (BABL_CR),
NULL);
- babl_pixel_format_new (
- "yuv422",
- "id", BABL_YUV422,
+ babl_format_new (
+ "y'cbcr411",
+ "id", BABL_YCBCR411,
"planar",
- babl_type ("u8"),
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
babl_sampling (1, 1),
- babl_component ("Y"),
- babl_sampling (2, 1),
+ babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_sampling (4, 1),
babl_component_id (BABL_CB),
- babl_sampling (2, 1),
+ babl_sampling (4, 1),
babl_component_id (BABL_CR),
NULL);
-#endif
}
#include "babl.h"
+
+static inline void
+convert_double_u16_scaled (double min_val,
+ double max_val,
+ unsigned short min,
+ unsigned short max,
+ void *src,
+ void *dst,
+ int n)
+{
+ while (n--)
+ {
+ double dval = *(double *) src;
+ unsigned short u16val;
+
+ if (dval < min_val)
+ u16val = min;
+ else if (dval > max_val)
+ u16val = max;
+ else
+ u16val = (dval-min_val) / (max_val-min_val) * (max-min) + min;
+
+ *(unsigned short *) dst = u16val;
+ dst += 2;
+ src += 8;
+ }
+}
+
+static inline void
+convert_u16_double_scaled (double min_val,
+ double max_val,
+ unsigned short min,
+ unsigned short max,
+ void *src,
+ void *dst,
+ int n)
+{
+ while (n--)
+ {
+ int u16val = *(unsigned short*) src;
+ double dval;
+
+ if (u16val < min)
+ dval = min_val;
+ else if (u16val > max)
+ dval = max_val;
+ else
+ dval = (u16val-min) / (double)(max-min) * (max_val-min_val) + min_val;
+
+ (*(double *) dst) = dval;
+ dst += 8;
+ src += 1;
+ }
+}
+
+
+
static void
convert_double_u16 (void *src,
void *dst,
}
}
+
+/* source ICC.1:2004-10 */
+
+static void convert_double_u16_l (void *src, void *dst, int n){
+ convert_double_u16_scaled (0.0, 100.0, 0x00, 0xffff, src, dst, n);
+}
+static void convert_u16_l_double (void *src, void *dst, int n){
+ convert_u16_double_scaled (0.0, 100.0, 0x00, 0xffff, src, dst, n);
+}
+
+static void convert_double_u16_ab (void *src, void *dst, int n){
+ convert_double_u16_scaled (-128.0, 127.0, 0x00, 0xffff, src, dst, n);
+}
+static void convert_u16_ab_double (void *src, void *dst, int n){
+ convert_u16_double_scaled (-128.0, 127.0, 0x00, 0xffff, src, dst, n);
+}
+
+
void
babl_base_type_u16 (void)
{
"bits", 16,
NULL);
+ babl_type_new (
+ "u16-CIE-L",
+ "id", BABL_U16_CIE_L,
+ "integer",
+ "unsigned",
+ "bits", 16,
+ "min_val", 0.0,
+ "max_val", 100.0,
+ NULL
+ );
+
+ babl_type_new (
+ "u16-CIE-ab",
+ "id", BABL_U16_CIE_AB,
+ "integer",
+ "unsigned",
+ "bits", 16,
+ "min_val", -50.0,
+ "max_val", 50.0,
+ NULL
+ );
+
+
babl_conversion_new (
"babl-base: u16 to double",
"source", babl_type_id (BABL_U16),
"linear", convert_double_u16,
NULL
);
+
+
+ babl_conversion_new (
+ "babl-base: u16-CIE-L to double",
+ "source", babl_type_id (BABL_U16_CIE_L),
+ "destination", babl_type_id (BABL_DOUBLE),
+ "linear", convert_u16_l_double,
+ NULL
+ );
+ babl_conversion_new (
+ "babl-base: double to u16-CIE-L",
+ "source", babl_type_id (BABL_DOUBLE),
+ "destination", babl_type_id (BABL_U16_CIE_L),
+ "linear", convert_double_u16_l,
+ NULL
+ );
+
+ babl_conversion_new (
+ "babl-base: u16-CIE-ab to double",
+ "source", babl_type_id (BABL_U16_CIE_AB),
+ "destination", babl_type_id (BABL_DOUBLE),
+ "linear", convert_u16_ab_double,
+ NULL
+ );
+ babl_conversion_new (
+ "babl-base: double to u16-CIE-ab",
+ "source", babl_type_id (BABL_DOUBLE),
+ "destination", babl_type_id (BABL_U16_CIE_AB),
+ "linear", convert_double_u16_ab,
+ NULL
+ );
}
#include "babl.h"
-static void
-convert_u8_double (void *src,
- void *dst,
- int n)
+static inline void
+convert_double_u8_scaled (double min_val,
+ double max_val,
+ unsigned char min,
+ unsigned char max,
+ void *src,
+ void *dst,
+ int n)
{
while (n--)
{
- (*(double *) dst) = (*(unsigned char *) src/255.0);
- dst += 8;
- src += 1;
+ double dval = *(double *) src;
+ unsigned char u8val;
+
+ if (dval < min_val)
+ u8val = min;
+ else if (dval > max_val)
+ u8val = max;
+ else
+ u8val = (dval-min_val) / (max_val-min_val) * (max-min) + min;
+
+ *(unsigned char *) dst = u8val;
+ dst += 1;
+ src += 8;
}
}
-static void
-convert_double_u8 (void *src,
- void *dst,
- int n)
+static inline void
+convert_u8_double_scaled (double min_val,
+ double max_val,
+ unsigned char min,
+ unsigned char max,
+ void *src,
+ void *dst,
+ int n)
{
while (n--)
{
- double dval = *(double *) src;
- unsigned char u8val;
+ int u8val = *(unsigned char *) src;
+ double dval;
- if (dval < 0)
- u8val = 0;
- else if (dval > 1)
- u8val = 255;
+ if (u8val < min)
+ dval = min_val;
+ else if (u8val > max)
+ dval = max_val;
else
- u8val = dval*255.0;
+ dval = (u8val-min) / (double)(max-min) * (max_val-min_val) + min_val;
- *(unsigned char *) dst = u8val;
- dst += 1;
- src += 8;
+ (*(double *) dst) = dval;
+ dst += 8;
+ src += 1;
}
}
+
+static void convert_u8_double (void *src, void *dst, int n){
+ convert_u8_double_scaled (0.0, 1.0, 0, 255, src, dst, n);
+}
+static void convert_double_u8 (void *src, void *dst, int n){
+ convert_double_u8_scaled (0.0, 1.0, 0, 255, src, dst, n);
+}
+
+static void convert_double_u8_luma (void *src, void *dst, int n){
+ convert_double_u8_scaled (0.0, 1.0, 16, 235, src, dst, n);
+}
+static void convert_u8_luma_double (void *src, void *dst, int n){
+ convert_u8_double_scaled (0.0, 1.0, 16, 235, src, dst, n);
+}
+
+static void convert_double_u8_chroma (void *src, void *dst, int n){
+ convert_double_u8_scaled (-0.5, 0.5, 16, 240, src, dst, n);
+}
+static void convert_u8_chroma_double (void *src, void *dst, int n){
+ convert_u8_double_scaled (-0.5, 0.5, 16, 240, src, dst, n);
+}
+
+/* source ICC.1:2004-10 */
+
+static void convert_double_u8_l (void *src, void *dst, int n){
+ convert_double_u8_scaled (0.0, 100.0, 0x00, 0xff, src, dst, n);
+}
+static void convert_u8_l_double (void *src, void *dst, int n){
+ convert_u8_double_scaled (0.0, 100.0, 0x00, 0xff, src, dst, n);
+}
+
+static void convert_double_u8_ab (void *src, void *dst, int n){
+ convert_double_u8_scaled (-128.0, 127.0, 0x00, 0xff, src, dst, n);
+}
+static void convert_u8_ab_double (void *src, void *dst, int n){
+ convert_u8_double_scaled (-128.0, 127.0, 0x00, 0xff, src, dst, n);
+}
+
+
void
babl_base_type_u8 (void)
{
"bits", 8,
NULL);
+ babl_type_new (
+ "u8-luma",
+ "id", BABL_U8_LUMA,
+ "bits", 8,
+ NULL
+ );
+
+ babl_type_new (
+ "u8-chroma",
+ "id", BABL_U8_CHROMA,
+ "integer",
+ "unsigned",
+ "bits", 8,
+ "min", (long) 16,
+ "max", (long)240,
+ "min_val", -0.5,
+ "max_val", 0.5,
+ NULL
+ );
+
+ babl_type_new (
+ "u8-CIE-L",
+ "id", BABL_U8_CIE_L,
+ "integer",
+ "unsigned",
+ "bits", 8,
+ "min_val", 0.0,
+ "max_val", 100.0,
+ NULL
+ );
+
+ babl_type_new (
+ "u8-CIE-ab",
+ "id", BABL_U8_CIE_AB,
+ "integer",
+ "unsigned",
+ "bits", 8,
+ "min_val", -50.0,
+ "max_val", 50.0,
+ NULL
+ );
+
babl_conversion_new (
"babl-base: u8 to double",
"source", babl_type_id (BABL_U8),
"destination", babl_type_id (BABL_DOUBLE),
- "linear", convert_u8_double,
+ "linear", convert_u8_double,
NULL
);
-
babl_conversion_new (
"babl-base: double to u8",
"source", babl_type_id (BABL_DOUBLE),
"destination", babl_type_id (BABL_U8),
- "linear", convert_double_u8,
+ "linear", convert_double_u8,
+ NULL
+ );
+
+
+ babl_conversion_new (
+ "babl-base: u8-luma to double",
+ "source", babl_type_id (BABL_U8_LUMA),
+ "destination", babl_type_id (BABL_DOUBLE),
+ "linear", convert_u8_luma_double,
+ NULL
+ );
+ babl_conversion_new (
+ "babl-base: double to u8-luma",
+ "source", babl_type_id (BABL_DOUBLE),
+ "destination", babl_type_id (BABL_U8_LUMA),
+ "linear", convert_double_u8_luma,
+ NULL
+ );
+
+ babl_conversion_new (
+ "babl-base: u8-chroma to double",
+ "source", babl_type_id (BABL_U8_CHROMA),
+ "destination", babl_type_id (BABL_DOUBLE),
+ "linear", convert_u8_chroma_double,
+ NULL
+ );
+ babl_conversion_new (
+ "babl-base: double to u8-chroma",
+ "source", babl_type_id (BABL_DOUBLE),
+ "destination", babl_type_id (BABL_U8_CHROMA),
+ "linear", convert_double_u8_chroma,
+ NULL
+ );
+
+ babl_conversion_new (
+ "babl-base: u8-CIE-L to double",
+ "source", babl_type_id (BABL_U8_CIE_L),
+ "destination", babl_type_id (BABL_DOUBLE),
+ "linear", convert_u8_l_double,
+ NULL
+ );
+ babl_conversion_new (
+ "babl-base: double to u8-CIE-L",
+ "source", babl_type_id (BABL_DOUBLE),
+ "destination", babl_type_id (BABL_U8_CIE_L),
+ "linear", convert_double_u8_l,
+ NULL
+ );
+
+ babl_conversion_new (
+ "babl-base: u8-CIE-ab to double",
+ "source", babl_type_id (BABL_U8_CIE_AB),
+ "destination", babl_type_id (BABL_DOUBLE),
+ "linear", convert_u8_ab_double,
+ NULL
+ );
+ babl_conversion_new (
+ "babl-base: double to u8-CIE-ab",
+ "source", babl_type_id (BABL_DOUBLE),
+ "destination", babl_type_id (BABL_U8_CIE_AB),
+ "linear", convert_double_u8_ab,
NULL
);
}
rgb_to_lab_to_rgb \
rgb_to_ycbcr \
rgb_to_ycbcr_to_rgb \
+ srgb_to_lab_u8 \
+ sanity \
babl_class_name
float_to_u8_SOURCES = float_to_u8.c
u8_to_float_SOURCES = u8_to_float.c
grayscale_to_rgb_SOURCES = grayscale_to_rgb.c
rgb_to_lab_to_rgb_SOURCES = rgb_to_lab_to_rgb.c
+srgb_to_lab_u8_SOURCES = srgb_to_lab_u8.c
rgb_to_ycbcr_SOURCES = rgb_to_ycbcr.c
rgb_to_ycbcr_to_rgb_SOURCES = rgb_to_ycbcr_to_rgb.c
babl_class_name_SOURCES = babl_class_name.c
+sanity_SOURCES = sanity.c
AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
static void model_html (Babl *babl);
static void type_html (Babl *babl);
-static void pixel_format_html (Babl *babl);
+static void format_html (Babl *babl);
static int each_item (Babl *babl,
void *user_data);
babl_model_each (each_item, NULL);
printf ("<tr><td><a name='Pixel-formats'></a> </td></tr>\n");
printf ("<tr><th>Pixel format</th><th>bytes/pixel</th><th>color model</th><th>bands</th> </tr>\n");
- babl_pixel_format_each (each_item, NULL);
+ babl_format_each (each_item, NULL);
printf ("</table>\n");
babl_destroy ();
case BABL_MODEL:
model_html (babl);
break;
- case BABL_PIXEL_FORMAT:
- pixel_format_html (babl);
+ case BABL_FORMAT:
+ format_html (babl);
break;
default:
break;
}
static void
-pixel_format_html (Babl *babl)
+format_html (Babl *babl)
{
int i;
printf ("<td valign='top'>");
{
int bytes=0;
- for (i=0; i< babl->pixel_format.bands; i++)
+ for (i=0; i< babl->format.bands; i++)
{
- bytes += BABL(babl->pixel_format.type[i])->type.bits/8;
+ bytes += BABL(babl->format.type[i])->type.bits/8;
}
printf ("<span class='name'>%i</span>", bytes);
}
printf ("</td>");
printf ("<td valign='top'>");
- printf ("<span class='name'>%s</span>", BABL(babl->pixel_format.model)->instance.name );
+ printf ("<span class='name'>%s</span>", BABL(babl->format.model)->instance.name );
printf ("</td>");
printf ("<td>");
- for (i=0; i< babl->pixel_format.bands; i++)
+ for (i=0; i< babl->format.bands; i++)
{
printf ("<span class='type'>%s </span><span class='component'>%s</span><span class='spacer'> </span><br/>",
- BABL(babl->pixel_format.type[i])->instance.name,
- BABL(babl->pixel_format.component[i])->instance.name );
+ BABL(babl->format.type[i])->instance.name,
+ BABL(babl->format.component[i])->instance.name );
}
printf ("</td>");
#if 0
int i;
- babl_log ("\t\tplanar=%i", babl->pixel_format.planar);
- babl_log ("\t\tbands=%i", babl->pixel_format.bands);
+ babl_log ("\t\tplanar=%i", babl->format.planar);
+ babl_log ("\t\tbands=%i", babl->format.bands);
- for (i=0; i< babl->pixel_format.bands; i++)
+ for (i=0; i< babl->format.bands; i++)
{
babl_log ("\t\tband[%i] type='%s' component='%s' sampling='%s'",
- i, babl->pixel_format.type[i]->instance.name,
- babl->pixel_format.component[i]->instance.name,
- babl->pixel_format.sampling[i]->instance.name);
+ i, babl->format.type[i]->instance.name,
+ babl->format.component[i]->instance.name,
+ babl->format.sampling[i]->instance.name);
}
#endif
}
{BABL_SAMPLING, "BablSampling"},
{BABL_COMPONENT, "BablComponent"},
{BABL_MODEL, "BablModel"},
- {BABL_PIXEL_FORMAT, "BablPixelFormat"},
+ {BABL_FORMAT, "BablFormat"},
{BABL_CONVERSION, "BablConversion"},
{BABL_CONVERSION_TYPE, "BablConversionType"},
{BABL_CONVERSION_TYPE_PLANAR, "BablConversionTypePlanar"},
{BABL_CONVERSION_MODEL_PLANAR, "BablConversionModelPlanar"},
- {BABL_CONVERSION_PIXEL_FORMAT, "BablConversionPixelFormat"},
- {BABL_CONVERSION_PIXEL_FORMAT_PLANAR, "BablConversionPixelFormatPlanar"},
+ {BABL_CONVERSION_FORMAT, "BablConversionFormat"},
+ {BABL_CONVERSION_FORMAT_PLANAR, "BablConversionFormatPlanar"},
{BABL_FISH, "BablFish"},
{BABL_FISH_REFERENCE, "BablFishReference"},
{BABL_IMAGE, "BablImage"},
fish = babl_fish (
- babl_pixel_format_new (
+ babl_format_new (
"foo",
babl_model ("gray"),
babl_type ("float"),
babl_component ("Y"),
NULL
),
- babl_pixel_format_new (
+ babl_format_new (
"bar",
babl_model ("gray"),
babl_type ("u8"),
NULL
));
- babl_fish_process (fish,
+ babl_process (fish,
float_buf, u8_buf,
BUFFER_LENGTH);
fish = babl_fish (
- babl_pixel_format_new (
+ babl_format_new (
"foo",
babl_model ("gray"),
babl_type ("float"),
babl_component ("Y"),
NULL
),
- babl_pixel_format_new (
+ babl_format_new (
"bar",
babl_model ("rgb"),
babl_type ("float"),
)
);
- babl_fish_process (fish,
+ babl_process (fish,
grayscale_buf, rgb_buf,
PIXELS);
fish = babl_fish (
- babl_pixel_format_new (
+ babl_format_new (
"foo",
babl_model ("rgb"),
babl_type ("float"),
babl_component ("B"),
NULL
),
- babl_pixel_format_new (
+ babl_format_new (
"bar",
babl_model ("CIE Lab"),
babl_type ("float"),
)
);
- babl_fish_process (fish, source_buf, temp_buf, PIXELS);
+ babl_process (fish, source_buf, temp_buf, PIXELS);
- fish = babl_fish (babl_pixel_format ("bar"),
- babl_pixel_format ("foo"));
+ /* this test tests both pixel format creation, and the scope of
+ * babl_fish()'s polymorphism
+ */
+ fish = babl_fish ("bar","foo");
- babl_fish_process (fish, temp_buf, destination_buf, PIXELS);
+ babl_process (fish, temp_buf, destination_buf, PIXELS);
for (i=0; i<PIXELS * 3; i++)
{
int OK=1;
fish = babl_fish (
- babl_pixel_format_new (
+ babl_format_new (
"foo",
babl_model ("rgb"),
babl_type ("float"),
babl_component ("B"),
NULL
),
- babl_pixel_format_new (
+ babl_format_new (
"bar",
- babl_model ("ycbcr"),
+ babl_model ("y'cbcr"),
babl_type ("float"),
babl_component ("Y"),
babl_component ("Cb"),
)
);
- babl_fish_process (fish, source_buf, destination_buf, PIXELS);
+ babl_process (fish, source_buf, destination_buf, PIXELS);
for (i=0; i<PIXELS * 3; i++)
{
int OK=1;
fish = babl_fish (
- babl_pixel_format_new (
+ babl_format_new (
"foo",
babl_model ("rgb"),
babl_type ("float"),
babl_component ("B"),
NULL
),
- babl_pixel_format_new (
+ babl_format_new (
"bar",
- babl_model ("ycbcr"),
+ babl_model ("y'cbcr"),
babl_type ("float"),
babl_component ("Y"),
babl_component ("Cb"),
)
);
- babl_fish_process (fish, source_buf, temp_buf, PIXELS);
+ babl_process (fish, source_buf, temp_buf, PIXELS);
- fish = babl_fish (babl_pixel_format ("bar"),
- babl_pixel_format ("foo"));
+ fish = babl_fish (babl_format ("bar"),
+ babl_format ("foo"));
- babl_fish_process (fish, temp_buf, destination_buf, PIXELS);
+ babl_process (fish, temp_buf, destination_buf, PIXELS);
for (i=0; i<PIXELS * 3; i++)
{
--- /dev/null
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <math.h>
+#include "babl.h"
+#include "babl-internal.h"
+
+#define PIXELS 6
+#define TOLERANCE 0
+
+unsigned char source_buf [PIXELS*3]=
+ { 0, 0, 0,
+ 127, 127, 127,
+ 255, 255, 255,
+ 255, 0.0, 0.0,
+ 0.0, 255, 0.0,
+ 0.0, 0.0, 255};
+
+unsigned char reference_buf [PIXELS*3]=
+ { 0, 0, 0,
+ 127, 0, 0,
+ 255, 255, 255,
+ 0, 0, 0,
+ 0, 0, 0,
+ 0, 0, 0};
+
+unsigned char destination_buf [PIXELS*3];
+
+int
+test (void)
+{
+ int i;
+ int OK=1;
+
+ babl_process (babl_fish ("srgb", "cie-lab-u8"),
+ source_buf, destination_buf,
+ PIXELS);
+
+ for (i=0; i<PIXELS * 3; i++)
+ {
+ if ((destination_buf[i] - reference_buf[i]) > TOLERANCE)
+ {
+ babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %i should be %i",
+ i, i,i%3, i,i/3, destination_buf[i], reference_buf[i]);
+ OK=0;
+ }
+ }
+ if (!OK)
+ return -1;
+ return 0;
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ babl_init ();
+ if (test())
+ return -1;
+ babl_destroy ();
+ return 0;
+}
fish = babl_fish (
- babl_pixel_format_new (
+ babl_format_new (
"foo",
babl_model ("gray"),
babl_type ("u8"),
babl_component ("Y"),
NULL
),
- babl_pixel_format_new (
+ babl_format_new (
"bar",
babl_model ("gray"),
babl_type ("float"),
NULL
));
- babl_fish_process (fish,
+ babl_process (fish,
u8_buf, float_buf,
BUFFER_LENGTH);